package org.rockyang.shardingjdbc.cusalgo.service;

import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.rockyang.shardingjdbc.base.exception.BizException;
import org.rockyang.shardingjdbc.mybatisplus.common.model.Order;
import org.rockyang.shardingjdbc.mybatisplus.common.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TestXATransactionService {

    @Autowired
    private IOrderService orderService;

    @Transactional
    @ShardingTransactionType(TransactionType.XA)
    public void testInsertTransaction(){

        Order order1 = new Order(111L,2L);
        Order order2 = new Order(222L,1L);
        orderService.add(order1);

        orderService.add(order2);
        throw new BizException("未知异常");
    }


}
